<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="lib/vue.js"></script>
</head>
<body>
<div id="root">
    <one :num="num" :set-num = "setNum"></one>
    <two :num="num" @set-num = "setNum"></two>
    <three :num="num" @update:num = "setNum"></three>
    <four :num="num" @update:num = "n=>num=n"></four>
    <!--  four的语法糖  -->
    <four :num.sync="num"></four>
</div>
</body>
<script>
new Vue({
    el: "#root",
    data:{
        num:100
    },
    methods:{
        setNum(num){
            this.num = num
        }
    },
    components:{
        one:{
            props:["num","set-num"],
            template:`
                <button @click="setNum(1)">{{num}}</button>
            `
        },
        two:{
            props:["num"],
            template:`
              <button @click="$emit('set-num',2)">{{num}}</button>
            `
        },
        three:{
            props:["num"],
            template:`
              <button @click="$emit('update:num',3)">{{num}}</button>
            `
        },
        four:{
            props:["num"],
            template:`
              <button @click="$emit('update:num',4)">{{num}}</button>
            `
        }
    }
})
</script>
</html>